//
//  CZDetailLoadingCell.swift
//  GZWeibo007
//
//  Created by apple on 15/12/24.
//  Copyright © 2015年 Apple. All rights reserved.
//

import UIKit

//TODO - : 后需要用到的Cell模型在此添加
enum CZDetailIdentifier:String{
    case DetailNomarlCell = "DetailNomarlCell"
    case DetailForwardCell = "DetailForwardCell"
    case DetailCommentCell = "DetailCommentCell"
    
    
    // 判断你点击的ID类型
    static func cellID(object : AnyObject) ->String {
        if object is CZStatus {
            //有转发微博的retweeted_status，就是转发微博
            return (object as! CZStatus).retweeted_status == nil ? DetailNomarlCell.rawValue : DetailForwardCell.rawValue
        }
        return DetailNomarlCell.rawValue
    }
}


class CZDetailLoadingCell: CZDetailCommentCell {

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        prepareUI()
    }
    
    
    override func prepareForReuse() {
        super.prepareForReuse()
        loadingView.startAnimating()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - 准备UI
    override func prepareUI() {
        //添加子控件
        contentView.addSubview(loadingView)
        contentView.addSubview(messageLabel)
        
        //添加约束
        loadingView.translatesAutoresizingMaskIntoConstraints = false
        messageLabel.translatesAutoresizingMaskIntoConstraints = false
        
        contentView.addConstraint(NSLayoutConstraint(item: loadingView, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: contentView, attribute: NSLayoutAttribute.CenterX, multiplier: 1, constant: -40))
        
        contentView.addConstraint(NSLayoutConstraint(item: loadingView, attribute: NSLayoutAttribute.CenterY, relatedBy: NSLayoutRelation.Equal, toItem: contentView, attribute: NSLayoutAttribute.CenterY, multiplier: 1, constant: 0))
        
        contentView.addConstraint(NSLayoutConstraint(item: messageLabel, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem: loadingView, attribute: NSLayoutAttribute.Right, multiplier: 1, constant: 5))
        
        contentView.addConstraint(NSLayoutConstraint(item: messageLabel, attribute: NSLayoutAttribute.CenterY, relatedBy: NSLayoutRelation.Equal, toItem: contentView, attribute: NSLayoutAttribute.CenterY, multiplier: 1, constant: 0))
        
        contentView.addConstraint(NSLayoutConstraint(item: contentView, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: 44))
    }
    
    //MARK:-懒加载
    /// 菊花
    private lazy var loadingView: UIActivityIndicatorView = {
      let view = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.Gray)
        view.color = UIColor.magentaColor()
        view.startAnimating()
        view.hidesWhenStopped = false
        
        return view
    }()
    
    /// 文字
    private lazy var messageLabel: UILabel = {
      let label = UILabel()
        
      label.text = "正在加载数据...."
      label.textColor = UIColor.lightGrayColor()
      label.sizeToFit()
        
      return label
    }()
}
